#ifndef VISUALPOSITIONSELECTOR_H
#define VISUALPOSITIONSELECTOR_H

#include <QWidget>
#include <QButtonGroup>
#include <QGridLayout>
#include <QPushButton>
#include <QPaintEvent>
#include <QPainter>
#include <QMouseEvent>
#include <QToolTip>

class VisualPositionSelector : public QWidget
{
    Q_OBJECT

public:
    explicit VisualPositionSelector(QWidget *parent = nullptr);

    // 页码位置枚举（与ProcessingSettings保持一致）
    enum Position {
        TopLeft = 0, TopCenter = 1, TopRight = 2,
        MiddleLeft = 3, MiddleCenter = 4, MiddleRight = 5,
        BottomLeft = 6, BottomCenter = 7, BottomRight = 8
    };

    void setSelectedPosition(Position position);
    Position getSelectedPosition() const { return m_selectedPosition; }

    // 设置样式
    void setCellSize(int size);
    void setSpacing(int spacing);
    void setSelectedColor(const QColor& color);
    void setHoverColor(const QColor& color);

signals:
    void positionChanged(Position position);
    void positionSelected(Position position);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void leaveEvent(QEvent *event) override;

private slots:
    void onButtonClicked(int position);

private:
    void setupUI();
    void updateButtonStates();
    QString getPositionName(Position position) const;
    QString getPositionDescription(Position position) const;

    QGridLayout* m_layout;
    QButtonGroup* m_buttonGroup;
    QList<QPushButton*> m_positionButtons;
    Position m_selectedPosition = BottomCenter;
    Position m_hoveredPosition = BottomCenter;

    // 样式属性
    int m_cellSize = 40;
    int m_spacing = 4;
    QColor m_selectedColor = QColor(52, 152, 219);    // iOS蓝
    QColor m_hoverColor = QColor(142, 198, 252);      // 浅蓝
    QColor m_baseColor = QColor(236, 240, 241);       // 浅灰
    QColor m_borderColor = QColor(189, 195, 199);     // 边框灰
};

#endif // VISUALPOSITIONSELECTOR_H